<!-- 代练丸子余额查询区域 -->
<div class="layui-form-item" style="margin-bottom: 15px;">
    <label class="layui-form-label" style="width: 100px;">代练丸子余额</label>
    <div class="layui-input-block">
        <div class="layui-input-inline" style="width: 120px;">
            <input type="text" id="DaiLianWangZiBalance" name="DaiLianWangZiBalance" placeholder="请点击查询"
                class="layui-input" readonly>
        </div>
        <button class="layui-btn" id="DaiLianWangZi_query_BalanceButton">查询余额</button>
    </div>
</div>
<script>
    /**
     * 获取代练丸子余额
     */
    window.DaiLianTong_getWanziBalance = async () => {
        // 调用获取余额API
        axios({
            url: '/api/dailianwanzi/get_my_balance/',
        }).then(res => {
            res = res.data;
            if (res.code === 0 && res.data && res.data.balance) {
                wanziBalance = parseFloat(res.data.balance);
                document.getElementById('DaiLianWangZiBalance').value = wanziBalance.toFixed(2) + ' 元';
                layer.msg('查询余额成功', { icon: 6 });
            } else {
                layer.msg('查询余额失败：' + (res.message || '未知错误'), { icon: 5 });
            }
        }).catch(error => {
            layer.msg('网络错误，无法查询余额', { icon: 5 });
            console.error('查询余额失败：', error);
        })
    }

    document.getElementById('DaiLianWangZi_query_BalanceButton').addEventListener('click', async () => {
        await window.DaiLianTong_getWanziBalance();
    });

</script>